﻿using System;
using System.Text;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace time
{
    [TestFixture]
    public class vancl_my2
    {
        private ISelenium selenium;
        private StringBuilder verificationErrors;
        //private StringBuilder error;

        [SetUp]
        public void SetupTest()
        {
            selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.vancl.com/");
            selenium.Start();
            verificationErrors = new StringBuilder();
        }

        [TearDown]
        public void TeardownTest()
        {
            try
            {
                //selenium.Stop();
            }
            catch (Exception)
            {
            }
        }

        [Test]
        public void t1()
        {
            selenium.Open("http://my.vancl.com");
            selenium.WindowMaximize();
            //selenium.WaitForPageToLoad("30000");
            Thread.Sleep(5000);

            if (!selenium.IsElementPresent("退出登录"))
            {
                //Console.Write("true");
                if ("https://login.vancl.com/Login/Login.aspx?http://my.vancl.com/" == selenium.GetLocation())
                {
                    if (selenium.IsElementPresent("id=vanclUserName"))
                    {
                        string username = "zz130750@163.com";
                        string password = "111111";
                        selenium.Type("id=vanclUserName", username);
                        selenium.Type("id=vanclPassword", password);
                        selenium.Click("id=vanclLogin");

                        Thread.Sleep(2000);
                        if (selenium.IsElementPresent("id=DropTitle"))
                        {
                            selenium.Click("id=DropTitle");
                        }
                        Thread.Sleep(5000);
                    }
                    //Console.Write("true");
                }
            }

            string stra = common.JsHelp.geta();
            String[] a = selenium.GetEval(stra).Split(','); // Split the string.

            foreach (var item in a)
            {
                try
                {

                    if (item.IndexOf(@"http://my.vancl.com") != -1)
                    {
                        selenium.Open(item);
                        System.Threading.Thread.Sleep(2000);

                        if (!selenium.IsElementPresent("//title"))
                        {
                            Console.Write(selenium.GetLocation() + " no title \n\r");
                        }
                        //selenium.GoBack();
                    }

                }
                catch (Exception ee)
                {
                    common.LogHelp.writelog(ee.ToString());
                    continue;
                }
            }
        }
    }
}